package com.micai.springboot.controller.admin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.micai.springboot.entity.RoleEntity;
import com.micai.springboot.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 描述：角色管理
 * <p>
 * Author: 赵新国
 * Date: 2017/11/14 15:21
 */
@Controller
@RequestMapping("/admin/role")
public class AdminRoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 分页查询角色列表
     * @param model
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/list")
    public String list(@RequestParam(value="pageNum", defaultValue="1") int pageNum,
                       @RequestParam(value="pageSize", defaultValue="5") int pageSize,
                       @RequestParam(required = false) String name, Model model) {
        Page<RoleEntity> roleDtos = roleService.getRoleByPage(pageNum, pageSize, name);
        if (roleDtos == null && roleDtos.getResult().isEmpty()) {
            return null;
        }
        PageInfo<RoleEntity> page = new PageInfo<RoleEntity>(roleDtos);
        model.addAttribute("page",page);
        // 参数回显
        model.addAttribute("name", name);
        return "admin/role/roleList";
    }
}
